﻿using System;
using System.Collections.ObjectModel;
using Moq;
using Prompts.Prompting.Model;
using Prompts.Service.PromptService;
using Prompts.Service.ReportExecution;

namespace Test.Prompts.Infrastructure.Fakes
{
    internal class FakeChildPromptLevelServiceClient
    {
        private readonly Mock<IChildPromptLevelServiceClient> _childTreeNodeService;
        private Action<GetChildrenResponse> _callback;

        public FakeChildPromptLevelServiceClient()
        {
            _childTreeNodeService = new Mock<IChildPromptLevelServiceClient>();
        }

        public void SetupGetChildren2(
            string promptName,
            string parameterName,
            string value)
        {
            var setup = _childTreeNodeService
                .Setup(
                    s => s.GetChildren2Async(
                        promptName
                        , parameterName
                        , It.Is<ParameterValue>(v => v.valueField == value)
                        , It.IsAny<Action<GetChildrenResponse>>()));

            setup.Callback<
                string,
                string,
                ParameterValue,
                Action<GetChildrenResponse>>(
                    (s, s2, pv, callback) => _callback = callback);
        }

        public void SetupGetChildren(
            string promptName,
            string parameterName, 
            ObservableCollection<ParameterValue> parameterValues)
        {
            var setup = _childTreeNodeService
                .Setup(
                    s => s.GetChildrenAsync(
                        promptName
                        , parameterName
                        , parameterValues
                        , It.IsAny<Action<GetChildrenResponse>>()));

            setup.Callback<
                string,
                string,
                ObservableCollection<ParameterValue>,
                Action<GetChildrenResponse>>(
                    (s, s2, pv, callback) => _callback = callback);
        }

        public void RaiseGetChildren2Completed(GetChildrenResponse getChildrenResponse)
        {
            _callback(getChildrenResponse);
        }

        public void RaiseGetChildrenCompleted(GetChildrenResponse getChildrenResponse)
        {
            _callback(getChildrenResponse);
        }

        public IChildPromptLevelServiceClient Object
        {
            get { return _childTreeNodeService.Object; }
        }
    }
}
